import java.util.List;
import java.util.Map;

import org.hibernate.Session;
import org.rbac.dao.BaseDao;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;

public class UpdateProductPath {

    
    
    
    public static void udpateImagePath() throws Exception{
        ClassPathXmlApplicationContext cpa = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        PlatformTransactionManager txManager=(PlatformTransactionManager) cpa.getBean("transactionManager");
        TransactionDefinition txDefinition =(TransactionDefinition) cpa.getBean("txDefinition");
        TransactionStatus status = txManager.getTransaction(txDefinition);
        BaseDao rbacdao=(BaseDao) cpa.getBean("rbacBaseDao");
        
        try {
            Session session =rbacdao.getSession();
            String hql="select new map(CName,CValue) from PubConst where CRetention=0";
            List<Map> lis=(List<Map>) rbacdao.queryForList(hql);
            for (Map map : lis) {
                System.out.println(map);
            }
            
            /*ScrollableResults customers = session.                
                    createQuery(" from  WebsiteProduct")
                    .setCacheMode(CacheMode.IGNORE)
                    .scroll(ScrollMode.FORWARD_ONLY);
                    int count=0;
                    while ( customers.next() ) {
                        WebsiteProduct wp = (WebsiteProduct) customers.get(0);
                        wp.setPPreview(wp.getPPreview().substring(1));
                        rbacdao.save(wp);
                    if ( ++count % 50 == 0 ) {
                    //flush a batch of updates and release memory:
                    session.flush();
                    session.clear();
                    }
                    }*/
            txManager.commit(status);
        } catch (Exception e) {
            txManager.rollback(status);
            e.printStackTrace();
        }
      
                
        
       
    }
    public static void main(String[] args) throws Exception {
         UpdateProductPath.udpateImagePath();
    }
}
